package com.wsl.tibet_goods.contorller;

import com.dym.util.Result;
import com.wsl.pojo.Tb_goods;
import com.wsl.pojo.Tb_gouwuche;
import com.wxl.service.Tb_goodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods")
public class Tb_goodsContorller {
    @Autowired
    private Tb_goodsService tb_goodsService;
    //商品审核
    @RequestMapping("/Audit/{id}")
    public void CommodityAudit(@PathVariable("id") Long goodsId){
        tb_goodsService.CommodityAudit(goodsId);
    }
    //下架
    @RequestMapping("/OffTheShelf/{id}")
    public void OffTheShelf(@PathVariable("id") Long goodsId){
        tb_goodsService.OffTheShelf(goodsId);
    }
    //上架
    @RequestMapping("/PutOnTheShelf/{id}")
    public void PutOnTheShelf(@PathVariable("id") Long goodsId){
        tb_goodsService.PutOnTheShelf(goodsId);
    }
    //批量上架
    @RequestMapping("/BatchListing")
    public void BatchListing(@RequestBody Long[] goodsId){
        tb_goodsService.BatchListing(goodsId);
    }
    //批量下架
    @RequestMapping("/TheBatchFromTheShelves")
    public void TheBatchFromTheShelves(@RequestBody Long[] goodsId){
        tb_goodsService.TheBatchFromTheShelves(goodsId);
    }
    //逻辑删除
    @RequestMapping("/delete/{id}")
    public void delete(@PathVariable("id") Long goodsId){
        tb_goodsService.delete(goodsId);
    }
    @RequestMapping("/ingoods")
    public Result intergoodds(@RequestBody Tb_gouwuche tb_gouwuche){
        try{
            tb_goodsService.intergoodds(tb_gouwuche);
            return new Result(true,"添加购物车成功");
        }catch (Exception ex){
            ex.printStackTrace();
            return new Result(false,"添加购物车失败");
        }
    }
    @RequestMapping("/xiadan")
    public Result xiadan(){
        try {
            tb_goodsService.xiadan();
            return new Result(true,"下单成功");
        }catch (Exception ex){
            ex.printStackTrace();
            return new Result(false,"下单失败");
        }
    }
}
